Collaborating:
You and your collaborators (including your
future self) can access the code and its history
Reproducible:
Your code runs and produces identical results
at different time points and on different systems
Colloquium | 13/01/2021
You and your collaborators (including your
future self) can access the code and its history
Your code runs and produces identical results
at different time points and on different systems
pwd)git clone https://github.com/KirstenStark/colab_r_github
here-package (Müller, 2020) to define relative paths within the project: read.csv(here::here("data", "file_I_want.csv"))knitr (Xie, 2015, 2020) and tinytex (Xie, 2015, 2020; for pdfs) packagesinstall.packages("rmarkdown") (Allaire et al., 2017)install.packages("knitr") (Xie, 2015, 2020)install.packages("rmarkdown") (Allaire et al., 2017)install.packages("knitr") (Xie, 2015, 2020)install.packages("rmarkdown") (Allaire et al., 2017)install.packages("knitr") (Xie 2015, 2020)
knitr-package (Xie, 2014, 2015, 2020) to customize chunks and knitting process
{r cache=TRUE,message=FALSE,warning=FALSE,results="hide",error = TRUE}opts_chunk$set()-functionTinyTeX (Xie, 2010) is a light-weight, cross-platform distribution (install.packages("tinytex"); tinytex::install_tinytex())Papaja-package (Aust & Barth, 2020) contains an R Markdown template for APA manuscripts, and helper functions to report results and generate tables in APA-style#/*
rmarkdown::render(input = rstudioapi::getSourceEditorContext()$path,
output_format = rmarkdown::github_document()),
knit_root_dir = getwd()) #*/
update.packages(ask = FALSE, checkBuilt = TRUE))git --version. If “git: command not found”:xcode-select --install. Restart R.git config --global user.name 'your name'git config --global user.email 'email associated with your GitHub account'git config --global --list (Check whether everything worked)https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.gitC:/Program Files/R/R-4.0.2/library or the like)install.packages() to install packages in this local libraryrenv.lock fileinstall.packages(renv)renv::init()renv::snapshot(). This will write the current version of all packages that are used in the project to the lockfile.renv::restore()Instead of step #2, you can also select “Use renv with this project” during project creation.
Restoring someone else’s package versions:
projectname.Rproj file)renv::restore() to install the package versions from the renv.lock fileN:/)remotes::install_github() and the like. Note, however, that at least on Windows, you may need to install additional tools for building these packages (via renv::equip() and/or from https://cran.r-project.org/bin/windows/Rtools/).Rmd files) on this virtual systemDockerfile that can be shared via GitHubrocker/rstudio contains R and RStudiorocker/tidyverse adds the tidyverse packagesrocker/verse adds LaTeXdocker run -e PASSWORD=1234 -p 8787:8787 -v /path/to/your/project:/home/rstudio/ rocker/rstudio
-e PASSWORD=1234 -p 8787:8787 makes it possible to connect to RStudio (running in the container) from your web browser by opening http://localhost:8787 (username: rstudio, password: 1234)-v /path/to/your/project:/home/rstudio/ makes your project available within the containerrocker/rstudio is the name of the Docker image you have chosen aboveDockerfile
rocker/verse)renv::restore())rmarkdown::render(...))# This as a text file stored with the name "Dockerfile" in your project directory.
# Base image from Docker Hub, including R, RStudio, the tidyverse, and LaTeX
FROM rocker/verse:4.0.2
# Set working directory within the container
WORDIR /home/rstudio
# Install renv
RUN R -e "remotes::install_version('renv', version = '0.12.0', repos = 'http://cran.us.r-project.org')"
# Copy the lock file
COPY renv.lock renv.lock
# Install package versions stored in the lockfile
RUN R -e "renv::consent(provided = TRUE)"
RUN R -e "renv::restore(prompt = FALSE)"
# When the container is run, render the report / mansucript
ENTRYPOINT Rscript -e "rmarkdown::render('my_manuscript.Rmd')"
Dockerfile for you if you don’t have your own onegit clone https://github.com/username/random_numbers.git cd random_numbers
README.md file from the “Files” paneecho "This is my first GitHub repository" >> README.md
echo "git add -A" git commit -m "edited readme"
git push
install.packages(c("rmarkdown", "knitr")) to the consoleset.seed(1234) number <- sample(x = 0:10, size = 1, replace = FALSE) print(number)
install.packages("renv")renv::init()
* Project '~/random_numbers' loaded. [renv 0.12.0]”renv.lock from the “Files” pane in RStudioinstall.packages("cowsay")
set.seed(1234)
number <- sample(x = 0:10, size = 1, replace = FALSE)
text <- paste("My favorite number is", number)
cowsay::say(text, "cow")
renv::status()renv::snapshot() > y > EnterYou now have a (somewhat) reproducible analysis.